<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理/<small>档案管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>档案管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column prop="code" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="height" label="身高" align="center"></el-table-column>
                <el-table-column prop="weight" label="体重" align="center"></el-table-column>
                <el-table-column prop="phonenumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="sex" label="性别" align="center"></el-table-column>
                <el-table-column prop="minzu" label="名族" align="center"></el-table-column>
                <el-table-column prop="age" label="年龄" align="center"></el-table-column>
                <el-table-column prop="birthday" label="出生日期" align="center"></el-table-column>
                <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
                <el-table-column prop="huiyingzt" label="婚姻状态" align="center"></el-table-column>
                <el-table-column prop="jiankanggls" label="健康管理师" align="center"></el-table-column>
                <el-table-column prop="beizhu" label="备注" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleupdate(scope.row)">编辑</el-button><br/>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button><br/>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增会员档案" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="档案号" prop="code">
                                                <el-input v-model="formData.code"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身高" prop="height">
                                                <el-input v-model="formData.height"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="体重" prop="weight">
                                                <el-input v-model="formData.weight"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phonenumber">
                                                <el-input v-model="formData.phonenumber"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" :value="0"></el-option>
                                                    <el-option label="女" :value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="民族" prop="minzu">
                                                <el-input v-model="formData.minzu"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-input v-model="formData.birthday"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="邮箱" prop="email">
                                                <el-input v-model="formData.email"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态" prop="hunyingzt">
                                                <el-select v-model="formData.hunyingzt">
                                                    <el-option label="未婚" value="0"></el-option>
                                                    <el-option label="已婚" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="健康管理师" prop="jiankanggls">
                                                <el-input v-model="formData.jiangkanggls"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">

                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="备注" prop="beizhu">
                                                <el-input v-model="formData.beizhu" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>


                            <el-tab-pane label="病史" name="third">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="既往史">
                                                <el-input v-model="formData.jws" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="家族史">
                                                <el-input v-model="formData.jzs" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="过敏史">
                                                <el-input v-model="formData.gms" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="病史">
                                                <el-input v-model="formData.bs" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="慢性病">
                                                <el-input v-model="formData.msb" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->

            <div class="add-form">
                <el-dialog title="编辑会员档案" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="档案号" prop="code">
                                                <el-input v-model="formData.code"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身高" prop="height">
                                                <el-input v-model="formData.height"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="体重" prop="weight">
                                                <el-input v-model="formData.weight"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phonenumber">
                                                <el-input v-model="formData.phonenumber"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" :value="1"></el-option>
                                                    <el-option label="女" :value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="民族" prop="minzu">
                                                <el-input v-model="formData.minzu"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-input v-model="formData.birthday"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="邮箱" prop="email">
                                                <el-input v-model="formData.email"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态" prop="hunyingzt">
                                                <el-select v-model="formData.hunyingzt">
                                                    <el-option label="未婚" value="0"></el-option>
                                                    <el-option label="已婚" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="健康管理师" prop="jiankanggls">
                                                <el-input v-model="formData.jiankanggls"/>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="备注" prop="beizhu">
                                                <el-input v-model="formData.beizhu" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>



                            <el-tab-pane label="病史" name="third">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="既往史">
                                                <el-input v-model="formData.jws" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="家族史">
                                                <el-input v-model="formData.jzs" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="过敏史">
                                                <el-input v-model="formData.gms" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="病史">
                                                <el-input v-model="formData.bs" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="慢性病">
                                                <el-input v-model="formData.msb" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            memberIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();

            /*//默认选中第一个复选框，检查项信息置空
            this.activeName='first';
            this.memberIds=[];
            //发送请求，查询所有的检查项信息，转为json，赋值给tabledata
            axios.get("/member/findAll.do").then((resp)=>{
                if (resp.data.flag){
                    //查询成功
                    this.tableData=resp.data.data
                }else {
                    //查询失败
                    this.$message.error(res.data.message);
                }
            })*/
        },
        methods: {
            //编辑
            handleEdit() {
                //1.进行表单校验
                        alert("表单校验通过");
                        //表单校验通过
                        //发送ajax请求,将录入的数据（检查组基本信息，勾选的检查项）提交到后台进行处理
                        axios.post("/member/update.do",this.formData).then((res) => {
                            if (res.data.success) {
                                this.dialogFormVisible4Edit=false;
                                //执行成功
                                //弹出成功提示信息
                                this.$message("修改成功");
                            } else {
                                this.dialogFormVisible4Edit=false;
                                //执行失败
                                this.$message.error(res.data.message);
                            }

                        });
                this.dialogFormVisible4Edit = true;
                this.findPage();

            },
            //添加
            handleAdd() {
                //发送ajax请求,将表单数据提交到后台进行处理
                //?memberIds=" + this.memberIds
                axios.post("/member/add.do", this.formData).then((res) => {
                    if (res.data.success) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                        this.findPage();
                    } else {
                        //操作失败
                        this.$message.error(res.data.msg);
                    }
                }).finally(() => {
                    //清空数据
                    this.resetForm();
                    //清空复选框
                    this.memberIds = [];
                    //关闭表单
                    this.dialogFormVisible = false;
                    //重新进行分页查询
                   /* this.findPage();*/
                });
            },
            //分页查询
            findPage() {
                //请求后台
                axios.post("/member/findPage.do",this.pagination).then((res) => {
                    if(res.data.flag){
                        this.pagination.total = res.data.data.total;//总数据量给\
                        this.dataList = res.data.data.rows;//当前页展示的数据集合
                    }
                    //位VUE对象的模型数据赋值,基于双向数据绑定展示到页面
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible=true;
            },
            // 弹出编辑窗口
            handleupdate(row) {
                this.dialogFormVisible4Edit = true;
                this.formData={};
                this.activeNames = 'first';

                axios.get("/member/findById.do?id="+row.id).then((resp)=>{
                    if (resp.data.flag){
                        this.formData=resp.data.data;
                    }else {
                        this.$message.error(resp.data.message)
                    }
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("你确定要删除当前数据吗？","提示",{
                    type:'warning'
                }).then(()=>{
                    axios.get("/member/delete.do?id="+row.id).then((resp)=>{
                        if (resp.data.flag){
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                        }else {
                            this.$message.error(resp.data.message);
                        }
                    }).finally((resp=>{
                        this.findPage();
                    }))
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:"操作取消"
                    })
                }).finally(()=>{
                    this.findPage();
                })
            }
        }
    })
</script>
</html>
